package zjh_20230331;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.File;
import java.util.List;

public class Xml {
    public static void main(String[] args) {
        //文件路径
        File xmlfile = new File("D:\\kaifamiao\\code\\untitled2\\src\\zjh_20230331\\translate.xml");
        //SAXReader创建Document对象
        SAXReader saxReader = new SAXReader();
        try {
            //读
            Document read = saxReader.read(xmlfile);

            Element element = read.getRootElement();
            List<Element> elements = element.elements();

            for (Element l : elements) {
//                System.out.println(l.attribute("id"));
                System.out.println(l.attributeValue("id"));
                System.out.println(l.attributeValue("name"));
                System.out.println(l.attributeValue("gender"));
            }
        } catch (DocumentException e) {
            throw new RuntimeException(e);
        }
    }
}
